﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TcpSyncIMServer
{
    public class Sender
    {
        private string obj;
        public Sender(string obj)
        {
            this.obj = obj;
        }

        public void Send(string str)
        {
            try
            {
                TcpClient tcpClient = new TcpClient(obj, 5657);
                NetworkStream networkStream = tcpClient.GetStream();
                byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(str);
                networkStream.Write(data, 0, data.Length);
                networkStream.Close();
                tcpClient.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show("连接被目标主机拒绝");
            }
        }
    }
}
